/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PPreferencias.java
 *
 * Created on 7/06/2009, 07:32:17 PM
 */

package Principal;

import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class PPreferencias extends javax.swing.JDialog {

    boolean huboCambios;

    /** Creates new form PPreferencias */
    public PPreferencias(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        huboCambios = false;
        fldUrlBD.setText(Main.preferencias.urlBD);
        fldNombreBD.setText(Main.preferencias.nombreBD);
        fldLoginBD.setText(Main.preferencias.loginBD);
        fldPassBD.setText(Main.preferencias.passBD);
        fldUrlConsultas.setText(Main.preferencias.urlConsultas);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        fldUrlBD = new javax.swing.JTextField();
        fldNombreBD = new javax.swing.JTextField();
        fldLoginBD = new javax.swing.JTextField();
        fldPassBD = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        fldUrlConsultas = new javax.swing.JTextField();
        btnAceptar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Preferencias");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Conexion a Base de Datos"));

        jLabel1.setText("URL del Servidor (con puerto de acceso):");

        jLabel2.setText("Nombre de la base de datos:");

        jLabel3.setText("Usuario de la base de datos:");

        jLabel4.setText("Contraseña del usuario:");

        fldUrlBD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fldUrlBDActionPerformed(evt);
            }
        });
        fldUrlBD.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                fldUrlBDPropertyChange(evt);
            }
        });

        fldNombreBD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fldNombreBDActionPerformed(evt);
            }
        });
        fldNombreBD.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                fldNombreBDPropertyChange(evt);
            }
        });

        fldLoginBD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fldLoginBDActionPerformed(evt);
            }
        });
        fldLoginBD.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                fldLoginBDPropertyChange(evt);
            }
        });

        fldPassBD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fldPassBDActionPerformed(evt);
            }
        });
        fldPassBD.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                fldPassBDPropertyChange(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(fldUrlBD, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE)
                    .addComponent(fldNombreBD, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE)
                    .addComponent(fldLoginBD, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE)
                    .addComponent(fldPassBD, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(fldUrlBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(fldNombreBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(fldLoginBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(fldPassBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Consulta de Historiales"));

        jLabel5.setText("URL del servidor de la pagina:");

        fldUrlConsultas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fldUrlConsultasActionPerformed(evt);
            }
        });
        fldUrlConsultas.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                fldUrlConsultasPropertyChange(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(fldUrlConsultas, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel5)
                .addComponent(fldUrlConsultas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(10, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btnCancelar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnAceptar, btnCancelar});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAceptar)
                    .addComponent(btnCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        this.dispose();
}//GEN-LAST:event_btnCancelarActionPerformed

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
           if(JOptionPane.showConfirmDialog(this, "¿Deseas guardar los cambios?", "Guardar Cambios", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION){
                Preferencias temp = new Preferencias();
                temp.urlBD = fldUrlBD.getText();
                temp.nombreBD = fldNombreBD.getText();
                temp.loginBD = fldLoginBD.getText();
                temp.passBD = fldPassBD.getText();
                temp.urlConsultas = fldUrlConsultas.getText();
                Main.preferencias = temp;
                Main.guardaPreferencias();
            }
        this.dispose();
    }//GEN-LAST:event_btnAceptarActionPerformed

    private void fldUrlBDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fldUrlBDActionPerformed
        huboCambios = true;
    }//GEN-LAST:event_fldUrlBDActionPerformed

    private void fldNombreBDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fldNombreBDActionPerformed
        huboCambios = true;
    }//GEN-LAST:event_fldNombreBDActionPerformed

    private void fldLoginBDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fldLoginBDActionPerformed
        huboCambios = true;
    }//GEN-LAST:event_fldLoginBDActionPerformed

    private void fldPassBDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fldPassBDActionPerformed
        huboCambios = true;
    }//GEN-LAST:event_fldPassBDActionPerformed

    private void fldUrlConsultasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fldUrlConsultasActionPerformed
        huboCambios = true;
    }//GEN-LAST:event_fldUrlConsultasActionPerformed

    private void fldUrlBDPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_fldUrlBDPropertyChange
        huboCambios = true;
    }//GEN-LAST:event_fldUrlBDPropertyChange

    private void fldNombreBDPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_fldNombreBDPropertyChange
        huboCambios = true;
    }//GEN-LAST:event_fldNombreBDPropertyChange

    private void fldLoginBDPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_fldLoginBDPropertyChange
        huboCambios = true;
    }//GEN-LAST:event_fldLoginBDPropertyChange

    private void fldPassBDPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_fldPassBDPropertyChange
        huboCambios = true;
    }//GEN-LAST:event_fldPassBDPropertyChange

    private void fldUrlConsultasPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_fldUrlConsultasPropertyChange
        huboCambios = true;
    }//GEN-LAST:event_fldUrlConsultasPropertyChange

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                PPreferencias dialog = new PPreferencias(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JTextField fldLoginBD;
    private javax.swing.JTextField fldNombreBD;
    private javax.swing.JTextField fldPassBD;
    private javax.swing.JTextField fldUrlBD;
    private javax.swing.JTextField fldUrlConsultas;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables

}
